package com.linkstec;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

public class ListToArrayTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		List<String> list = new ArrayList<String>();
		 list.add("123");
		 list.add("234");
		 list.add(null);
		 list.add(null);
		 String listStr = list.toString();
		 System.out.println(listStr.substring(1,listStr.length()-1));
		 System.out.println("+++++++++++++++++++++++++++++++");
		 String utilStr = StringUtils.join(list, ",");
//		 String utilStr = StringUtils.join(list, ",");
		 System.out.println(utilStr);
		 System.out.println("+++++++++++++++++++++++++++++++");
		 String[] s = new String[list.size()];
		 String[]  sss = (String[]) list.toArray(s);
		 System.out.println(sss);
		 for (String ssssss :sss){
			 System.out.println(ssssss);
		 }
		 
		 String[] temp =  deleteArrayNull(sss);
		 for (String ssssss :temp){
			 System.out.println(ssssss);
		 }

	}

	public static String[] deleteArrayNull(String[] string) {
		String[] array = string;
		// 声明一个list
		List<String> list = new ArrayList<>(array.length);
		for (String str : array) {
			list.add(str);
		}

		// 删除空的值
		while (list.remove(null));

		// 将list 转换成数组
		String[] list2 = list.toArray(new String[list.size()]);
		// 返回删除空值后的数组
		return list2;
	}
}
